export class HighPassFilter {
  prevInput: number;
  alpha: number;
  prevOutput: number;
  constructor(cutoffFrequency, sampleRate) {
    const RC = 1.0 / (2 * Math.PI * cutoffFrequency);
    this.alpha = RC / (RC + 1 / sampleRate);
    this.prevInput = 0;
    this.prevOutput = 0;
  }

  filter(input) {
    const output = this.alpha * (this.prevOutput + input - this.prevInput);
    this.prevInput = input;
    this.prevOutput = output;
    return output;
  }
}
